$def with (find_matches, ia)

$ q = query_param('q')

<div id="contentHead">
    <div class="small sansserif grey" style="margin-bottom:5px;">
        <a href="/search/inside">$_("Search Inside")</a> /
        <a href="/search/inside?q=$q">$q</a>
    </div>
    <h1>
        $ia
    </h1>
</div>

<div id="contentBody">

$ result = find_matches(ia, q)
$ matches = result.get('matches', [])
$ scale = 2
$ xpadding = 50
$ ypadding = 50
$ par_num = 0
$ box_num = 0

$for match in matches:
    $ text = match['text']

    $for par in match['par']:
        $ par_num = par_num + 1
        $ page = par['page']
        <p class="lightgreen small sansserif">$_('On leaf number %(page_num)d:', page_num=page)</p>

        $ t = (par['t'] / scale) - ypadding
        $ r = (par['r'] / scale) + xpadding
        $ b = (par['b'] / scale) + ypadding
        $ l = (par['l'] / scale) - xpadding
        $ width = r - l
        $ height = b - t
        $ halfWidth = par['page_width'] * .5
        <div class="clipOut" id="clipout$par_num" style="position:relative;width:$(width)px;height:$(height)px;max-width:918px;overflow:hidden;padding-bottom:10px;">
            <div class="clipIn" id="clipin$par_num" style="position:absolute;clip:rect($(t)px $(r)px $(b)px $(l)px);top:-$(t)px;left:-$(l)px;">
                <a href="//archive.org/stream/$ia#page/n$(page-1)/search/$q">
                $if ia.endswith('goog'):
                    <img src="//archive.org/download/$ia/page/leaf$(page)_s$(scale).jpg" class="clipImg" width="$halfWidth"/></a>
                $else:
                    <img src="//archive.org/download/$ia/page/leaf$(page)_s$(scale).jpg" class="clipImg"/></a>
                $for box in par['boxes']:
                    $if 'r' not in box:
                        $continue
                    $ box_num = box_num + 1
                    <div class="snipHL" id="highlight$box_num" style="width:$((box['r']-box['l'])/scale)px;height:$((box['b']-box['t'])/scale)px;left:$((box['l']/scale))px;top:$((box['t']/scale))px;"></div>
            </div>
        </div>
</div>
